import java.util.HashMap;
import java.util.Map;

public class Test2 {
    //leetcode 1218 最长定差子序列
    public int longestSubsequence(int[] arr, int difference) {
        int n = arr.length;
        Map<Integer,Integer> hash = new HashMap<>();
        int ret = 1;
        for (int i = 0; i < n; i++) {
            hash.put(arr[i],hash.getOrDefault(arr[i] - difference,0) + 1);
            ret = Math.max(ret,hash.get(arr[i]));
        }
        return ret;
    }
}
